using StudentApi.Models;

namespace StudentApi.Common;

public class ApiResponse<T>
{
    public int Code { get; set; }
    public string Msg { get; set; } = null!;
    public T? Data { get; set; }

    public ApiResponse(int code, T? data, string msg)
    {
        Code = code;
        Data = data;
        Msg = msg;
    }

    public static ApiResponse<T> Success(T? data, string msg = "请求成功")
    {
        return new ApiResponse<T>(1000, data, msg);
    }

    public static ApiResponse<T> Fail(int code, string msg = "请求失败")
    {
        return new ApiResponse<T>(code, default, msg);
    }
}